/**
 * 
 */
package belote.webapp.struts.user;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.validator.GenericValidator;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 * @author Gwenn
 * 
 */
@SuppressWarnings("serial")
public class LoginForm extends ActionForm {

	// ========================================================================
	// ATTRIBUTS
	// ========================================================================

	private String login;

	private String password;

	private boolean remember;

	// ========================================================================
	// METHODES 'PUBLIC'
	// ========================================================================

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void reset(ActionMapping pMapping, HttpServletRequest pRequest) {

		super.reset(pMapping, pRequest);
		remember = false;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ActionErrors validate(ActionMapping pMapping, HttpServletRequest pRequest) {

		ActionErrors errors = new ActionErrors();

		// --- login
		if (GenericValidator.isBlankOrNull(login)) {
			errors.add("login", new ActionMessage("login.form.login.required"));
		}

		// --- password
		if (GenericValidator.isBlankOrNull(password)) {
			errors.add("password", new ActionMessage("login.form.password.required"));
		}

		return errors;
	}

	// ========================================================================
	// GETTERS & SETTERS
	// ========================================================================

	/**
	 * @param pLogin
	 *            the login to set
	 */
	public void setLogin(String pLogin) {
		this.login = pLogin;
	}

	/**
	 * @return the login
	 */
	public String getLogin() {
		return this.login;
	}

	/**
	 * @param pPassword
	 *            the password to set
	 */
	public void setPassword(String pPassword) {
		this.password = pPassword;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return this.password;
	}

	/**
	 * @param pRemember
	 *            the remember to set
	 */
	public void setRemember(boolean pRemember) {
		this.remember = pRemember;
	}

	/**
	 * @return the remember
	 */
	public boolean isRemember() {
		return this.remember;
	}
}
